<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <meta name="copyright" content="All Rights Reserved, Copyright (C) 2013, Wuyeguo, Ltd."/>
    <title>智能应急快速搭建平台V1.0</title>
    <script type="text/javascript" src="../../js/commonCss.js"></script>
    <script type="text/javascript" src="../../js/commonJs.js"></script>
</head>
<div class="easyui-layout" data-options="fit:true">
    <!-- Begin of toolbar -->
    <div id="wu-toolbar-ep">
        <div class="wu-toolbar-button">
            <a href="#" class="easyui-linkbutton" iconCls="icon-remove" onclick="over()" plain="true">结束流程</a>
        </div>
        <div class="wu-toolbar-search">
            <label>模版名称：</label><input id="name" class="wu-text" style="width:100px">
            <a href="#" class="easyui-linkbutton" iconCls="icon-search" onclick="doSearch()">开始检索</a>
        </div>
    </div>
    <!-- End of toolbar -->
    <table id="wu-datagrid-ep" class="easyui-datagrid" toolbar="#wu-toolbar-ep"></table>
</div>
<!-- Begin of easyui-dialog -->
<div id="wu-dialog-ep" class="easyui-dialog" data-options="closed:true,iconCls:'icon-save'" style="width:1100px; height:600px; padding:10px;">

</div>
<!-- End of easyui-dialog -->
<script type="text/javascript">

    /**
     * Name 查询
     */
    function doSearch(){
        //$('#tt').datagrid('load',{
          //  itemid: $('#itemid').val(),
            //productid: $('#productid').val()
        //});

        var paramData = {
            createTime: $('#createTime').val(),
            lastUpdateTime: $('#lastUpdateTime').val(),  //须要查询的对象
            id: $('#id').val(),
            name: $('#name').val()
        };
        console.log(JSON.stringify(paramData))



        $('#wu-datagrid-ep').datagrid('load',{paramData:JSON.stringify(paramData)});
    }


	/**
	* Name 添加记录
	*/
	function add(){
		$('#wu-form-ep').form('submit', {
			url:'',
			success:function(data){
				if(data){
					$.messager.alert('信息提示','提交成功！','info');
					$('#wu-dialog-ep').dialog('close');
				}
				else
				{
					$.messager.alert('信息提示','提交失败！','info');
				}
			}
		});
	}
	
	/**
	* Name 修改记录
	*/
	function edit(){
		$('#wu-form-ep').form('submit', {
			url:'',
			success:function(data){
				if(data){
					$.messager.alert('信息提示','提交成功！','info');
					$('#wu-dialog-ep').dialog('close');
				}
				else
				{
					$.messager.alert('信息提示','提交失败！','info');
				}
			}
		});
	}
	
	/**
	* Name 删除记录
	*/
	function remove(){
		$.messager.confirm('信息提示','确定要删除该记录？', function(result){
			if(result){
				var items = $('#wu-datagrid-ep').datagrid('getSelections');
				var ids = [];
				$(items).each(function(){
					ids.push(this.id);
				});
				//alert(ids);return;
				$.ajax({
					url:'/activiti/deleteByIds',
					data:'ids='+ids,
					success:function(data){
						if(data){
							$.messager.alert('信息提示','删除成功！','info');
                            $('#wu-datagrid-ep').datagrid();
						}
						else
						{
							$.messager.alert('信息提示','删除失败！','info');		
						}
					}	
				});
			}	
		});
	}

    function over(){
        $.messager.confirm('信息提示','确定要结束该流程？', function(result){
            if(result){
                var items = $('#wu-datagrid-ep').datagrid('getSelections');
                var ids = [];
                $(items).each(function(){
                    ids.push(this.id);
                });
                $.ajax({
                    type: 'POST',
                    contentType: "application/json;charset=UTF-8",
                    url: '/process/stopProcessInstance',
                    dataType: 'json',
                    data:'{"processInstanceId":"'+ids+'"}',
                    success:function(data){
                        //if(data){
                            $.messager.alert('信息提示','流程结束成功！','info');
                            $('#wu-datagrid-ep').datagrid();
                       // }
                       // else
                       // {
                        //    $.messager.alert('信息提示','流程结束失败！','info');
                       // }
                    }
                });
            }
        });

    }


	/**
	* Name 打开添加窗口
	*/
	function openAdd(){
		$('#wu-form-ep').form('clear');
		$('#wu-dialog-ep').dialog({
           // href: '/activiti/create',
            content:"<iframe scrolling='auto' frameborder='0' src='/activiti/create' style='width:100%; height:100%; display:block;'></iframe>",
			closed: false,
			modal:true,
            title: "添加信息",
            buttons: [{
                text: '确定',
                iconCls: 'icon-ok',
                handler: add
            }, {
                text: '取消',
                iconCls: 'icon-cancel',
                handler: function () {
                    $('#wu-dialog-ep').dialog('close');                    
                }
            }]
        });
	}
	
	/**
	* Name 打开修改窗口
	*/
	function openEdit(){
		$('#wu-form-ep').form('clear');
		var item = $('#wu-datagrid-ep').datagrid('getSelected');
        var id = item.id;
		$('#wu-dialog-ep').dialog({
            content:"<iframe scrolling='auto' frameborder='0' src='/activiti/editor?modelId="+id+"' style='width:100%; height:100%; display:block;'></iframe>",
            closed: false,
			modal:true,
            title: "修改信息",
            buttons: [{
                text: '确定',
                iconCls: 'icon-ok',
                handler: edit
            }, {
                text: '取消',
                iconCls: 'icon-cancel',
                handler: function () {
                    $('#wu-dialog-ep').dialog('close');                    
                }
            }]
        });
	}

    function showImage(){
        var item = $('#wu-datagrid-ep').datagrid('getSelected');
        var id = item.id;
        $('#wu-dialog-ep').dialog({
            content:"<iframe scrolling='auto' frameborder='0' src='/process/image?processInstanceId="+id+"' style='width:100%; height:100%; display:block;'></iframe>",
            closed: false,
            modal:true,
            title: "流程"
        });

    }


    function openUp(){
        var item = $('#wu-datagrid-ep').datagrid('getSelected');
        var id = item.id;
        var taskId = item.taskId;
        var formKey = item.formKey;
        var taskName = item.taskName;
        $('#wu-dialog-ep').dialog({
            // href: '/activiti/create',
            // content:"<iframe scrolling='auto' frameborder='0' src='/easyui/act/process/forms.html?processInstanceId='"+id+" style='width:100%; height:100%; display:block;'></iframe>",
            content:"<iframe scrolling='auto' frameborder='0' src='/easyui/act/process/forms.html?processInstanceId="+id+"&taskId="+taskId+"&formKey="+formKey+"&taskName="+taskName+"' style='width:100%; height:100%; display:block;'></iframe>",

            closed: false,
            modal:true,
            title: "添加信息",
            buttons: [{
                text: '确定',
                iconCls: 'icon-ok',
                handler: add
            }, {
                text: '取消',
                iconCls: 'icon-cancel',
                handler: function () {
                    $('#wu-dialog-ep').dialog('close');
                }
            }]
        });
    }

    function openTasksInfo(){
        var item = $('#wu-datagrid-ep').datagrid('getSelected');
        var id = item.id;
        var taskId = item.taskId;
        var taskName = item.taskName;
        $('#wu-dialog-ep').dialog({
            // href: '/activiti/create',
            // content:"<iframe scrolling='auto' frameborder='0' src='/easyui/act/process/forms.html?processInstanceId='"+id+" style='width:100%; height:100%; display:block;'></iframe>",
            content:"<iframe scrolling='auto' frameborder='0' src='/easyui/act/tasks/hi-tasksinfo.html?processInstanceId="+id+"&taskId="+taskId+"&taskName="+taskName+"' style='width:100%; height:100%; display:block;'></iframe>",

            closed: false,
            modal:true,
            title: "添加信息",
            buttons: [{
                text: '确定',
                iconCls: 'icon-ok',
                handler: add
            }, {
                text: '取消',
                iconCls: 'icon-cancel',
                handler: function () {
                    $('#wu-dialog-ep').dialog('close');
                }
            }]
        });
    }
	/**
	* Name 载入数据
	*/
    var paramData = {
        flag: "1"
       // assignee:"张翠三"
    };
	$('#wu-datagrid-ep').datagrid({
		//url:'temp/datagrid.php',
        url:'/process/findHistoryProcessInstance',
        queryParams:{paramData:JSON.stringify(paramData)},
		rownumbers:true,
        singleSelect: true,//true只能选择一行
		pageSize:20,
		pagination:true,
		fitColumns:true,
		fit:true,
        pageList: [10, 20, 50, 100, 150, 200],
        columns:[[
			{ checkbox:true},
			{ field:'id',title:'流程id',width:100,sortable:true,align:'center'},
            { field:'processDefinitionName',title:'流程名称',width:100,sortable:true,align:'center'
                ,
                formatter: function (value, data) {
                    return '<a style="color: blue;" href="javascript:openTasksInfo()">'+data.processDefinitionName+'</a>';
                }
            },
            { field:'processDefinitionVersion',
                title:'版本',width:100,
                align:'center',
                formatter: function (value, data) {
                    return '<a style="color: blue;" >V' + data.processDefinitionVersion + '.0</a>';
                }
            },
            { field:'deploymentId',
                title:'流程实例',
                width:100,
                align:'center',
                formatter: function (value, data) {
                    return '<a style="color: blue;" href="javascript:showImage()">流程图</a>';
                }
            },
            { field:'taskId',title:'环节Id',width:100,sortable:true,align:'center'},
            { field:'taskName',title:'当前环节',width:100,sortable:true,align:'center'
                ,
                formatter: function (value, data) {
                    return '<a style="color: blue;" href="javascript:openUp()">'+data.taskName+'</a>';
                }
            },
			{ field:'startTime',title:'创建时间',width:180,sortable:true,align:'center'}
		]]
	});
</script>